<template>
  <div class="ele-body">
    <!-- 搜索表单 -->
    <opeartion-search @search="reload" />
    <!-- 数据表格 -->
    <el-card shadow="never">
      <ele-pro-table
        ref="table"
        row-key="id"
        :columns="columns"
        :datasource="datasource"
        :need-page="true"
        @done="onDone"
      >
        <!-- 表头工具栏 -->

        <!-- 标题列 -->
        <template slot="title" slot-scope="{ row }">
          <i :class="row.icon"></i> {{ row.title }}
        </template>
      </ele-pro-table>
    </el-card>
  </div>
</template>
  <script>
import OpeartionSearch from './components/opeartion-search';
 import { AllOpeartionLog } from '@/api/systemmanager/opeartionlog';
export default {
  name: 'Opeartion',
  components: { OpeartionSearch },
  data() {
    return {
      // 表格列配置
      columns: [
        {
          columnKey: 'index',
          type: 'index',
          width: 50,
          align: 'center',
          showOverflowTooltip: true,
          fixed: 'left',
          label: '序号'
        },
        {
          prop: 'createDate',
          label: '时间',
          showOverflowTooltip: true,
          sortable: 'createDate'
        },
        {
          prop: 'account',
          label: '登录账号',
          showOverflowTooltip: true,
          sortable: 'account'
        },
        {
          prop: 'accountName',
          label: '登录姓名',
          showOverflowTooltip: true,
          align: 'center'
        },
        {
          prop: 'modules',
          label: '操作模块',
          showOverflowTooltip: true,
          align: 'center'
        },
        { prop: 'events', label: '操作事件', showOverflowTooltip: true },
        { prop: 'ip', label: '访问ip', showOverflowTooltip: true }
      ],

      // 当前编辑数据
      current: null,
      loading: false
    };
  },
  methods: {
    /* 表格数据源 */
    async datasource(params) {
      params.where.pageindex = params.page;
      params.where.pagesize = params.limit;

      //添加排序
      if (params.order.order == null || params.order.order == undefined) {
        params.where.orderBys = [{ sort: 'createDate', order: 1 }];
      } else {
        params.where.orderBys = [];
        params.where.orderBys.push({
          sort: params.sorter.column.sortable,
          order: params.order.order == 'asc' ? 0 : 1
        });
      }
      let data = await AllOpeartionLog(params.where);

      return {
        list: data.items,
        count: data.totalrecords
      };
    },

    /* 表格渲染完成回调 */
    onDone({ data }) {
      // 编辑弹窗编辑完成后 done 事件回传表单数据，使用 Object.assign 赋值给 current 即可修改表格的行数据
      if (this.current) {
        Object.assign(this.current, data);
      }
    },
    /* 刷新表格 */
    reload(where) {
      this.$refs.table.reload({ where: where });
    }
  }
};
</script>
    